﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FlatFileParser.Core.Attributes;
using FlatFileParser.Core.Enums;
using FlatFileParser.Core.Processor;

namespace TestApplication
{
    [ProcessorType(LineProcessingType.Full)]
    public class Person
    {
        [FullProcessorField(1, 5)]
        public int PersonId { get; set; }

        [FullProcessorField(2, 20)]
        public string FirstName { get; set; }

        [FullProcessorField(3, 20)]
        public string LastName { get; set; }

        [FullProcessorField(4, 3)]
        public int Age { get; set; }

        [FullProcessorField(5, 15)]
        public string Username { get; set; }

        [FullProcessorField(6, 20)]
        public string Email { get; set; }

        public static Person ParsePerson(string value)
        {
            var parser = new FileProcessor<Person>();
            var result = parser.ProcessString(value);

            if (result.Count() != 0)
            {
                return result.First();
            }

            return null;
        }
    }

    [ProcessorType(LineProcessingType.Full)]
    public class Address
    {
        [FullProcessorField(1, 25)]
        public string Street { get; set; }

        [FullProcessorField(2, 20)]
        public string City { get; set; }

        [FullProcessorField(3, 2)]
        public string State { get; set; }

        [FullProcessorField(4, 5)]
        public string ZipCode { get; set; }

        public static Address ParseAddress(string value)
        {
            var parser = new FileProcessor<Address>();
            var result = parser.ProcessString(value);

            if (result.Count() != 0)
            {
                return result.First();
            }

            return null;
        }
    }

    [ProcessorType(LineProcessingType.Full)]
    class ComplexType
    {
        [FullProcessorField(1, 83, "ParsePerson")]
        public Person Person { get; set; }

        [FullProcessorField(2, 52, "ParseAddress")]
        public Address Address { get; set; }
    }
}
